package cn.melonlib.record.oper.comp.service;

import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Component
public class OperationRecordScheduledWorker extends ApplicationObjectSupport {

    @Resource
    private OperationRecordSaveService operationRecordSaveService;

    @Scheduled(fixedDelay = 5)
    public void scheduledWorker() throws Exception{
        logger.info("ApiRecord:"+Thread.currentThread().getId());
        synchronized (operationRecordSaveService.getCached()) {
            if(operationRecordSaveService.getCached().size()>0) {
                operationRecordSaveService.storeLogs();
            }
            operationRecordSaveService.getCached().wait();

        }
    }
}
